<template>
  <div>
    <div class="background">
      <img class="img" src="../img/qingdao.png" alt="" />
      <div class="form">
        <el-card>
          <el-form
            :model="ruleForm"
            status-icon
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item
              ><h1 style="font-size: 24px; padding-left: 22px">
                找回密码
              </h1></el-form-item
            >
            <el-form-item required label="密码" prop="pass">
              <el-input
                type="password"
                v-model="ruleForm.pass"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item required label="确认密码" prop="checkPass">
              <el-input
                type="password"
                v-model="ruleForm.checkPass"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <!-- <el-form-item label="年龄" prop="age">
            <el-input v-model.number="ruleForm.age"></el-input>
          </el-form-item> -->
            <el-form-item>
              <el-button plain type="warning" @click="onSubmit">提交</el-button>
              <el-button plain type="primary" @click="resetForm"
                >取消</el-button
              >
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </div>
  </div>
</template>
<script >
import { restpassword } from "@/network/user";
export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        pass: "",
        checkPass: "",
      },
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }],
      },
    };
  },
  methods: {
    onSubmit() {
      restpassword(this.ruleForm).then((res) => {
        // if (res.status) {
          this.$message({
            message: "恭喜你，" + res.msg,
            type: "success",
          });
        this.$router.push("/");
        // }
        // else{
        //   this.$message.error(res.msg);
        // }
      });
    },
    resetForm() {
      this.$router.push("/");
    },
  },
};
</script>

</script>

<style>
.background {
  position: relative;

  /* display: inline-block; */
  z-index: 1;
}
.img {
  width: 100%;
  height: 80%;
  opacity: 0.5;
}
.form {
  margin-left: 30%;
  margin-bottom: 20%;
  position: absolute;
  bottom: 0;
  color: #fff;
  opacity: 1;
  z-index: 999;
}
.el-card__body {
  padding-left: 10px;
  padding-right: 50px;
  padding-top: 30px;
}
h1 {
  color: cadetblue;
}
</style>